 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.subway.rca.entity.ViewCkDataauditAirReportCheck;
import com.zdkj.subway.rca.service.ViewCkDataauditAirReportCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 所有运营商收入报表与对账数据复核
 *
 * @author stw
 * @date 2020-11-15 12:50:53
 */
@RestController
@AllArgsConstructor
@RequestMapping("/viewckdataauditairreportcheck" )
@Api(value = "viewckdataauditairreportcheck", tags = "报表调账-收入报表数据关联复核-所有运营商收入报表与对账数据复核")
public class ViewCkDataauditAirReportCheckController {

    private final ViewCkDataauditAirReportCheckService viewCkDataauditAirReportCheckService;
    /**
     * 报表调账-收入报表数据关联复核-机场城际收入报表与对账数据复核-生成数据
     * @return R
     */
    @ApiOperation(value = "生成数据", notes = "生成数据")
    @SysLog("报表调账-收入报表数据关联复核-所有运营商收入报表与对账数据复核-生成数据" )
    @GetMapping({"/generate"})
    @PreAuthorize("@pms.hasPermission('sw_ck_dataaudit_air_report_check_generate')" )
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
            }
    )
    public R generate(String startDate, String endDate) {
        try {
            if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
                return R.failed("开始日期和结束日期必选");
            }

            boolean flag = viewCkDataauditAirReportCheckService.generate(startDate,endDate);

            return R.ok(flag);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed();
        }

    }

    /**
     * 分页查询
     * @param page 分页对象
     * @param  conformStatus 
     * @param startDate
     * @param endDate
     * 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getViewCkDataauditAirReportCheckPage(Page page,String conformStatus, String startDate, String endDate) {
        ViewCkDataauditAirReportCheck viewCkDataauditAirReportCheck = new ViewCkDataauditAirReportCheck();
        return R.ok(viewCkDataauditAirReportCheckService.page(page, Wrappers.query(viewCkDataauditAirReportCheck).lambda()
                .eq(StringUtils.isNotEmpty(conformStatus), ViewCkDataauditAirReportCheck::getConformStatus, conformStatus)
                .ge(StringUtils.isNotEmpty(startDate), ViewCkDataauditAirReportCheck::getStatisticsDate, startDate)
                .le( StringUtils.isNotEmpty(endDate),ViewCkDataauditAirReportCheck::getStatisticsDate, endDate)
                .orderByDesc(ViewCkDataauditAirReportCheck::getStatisticsDate)
        ));
    }

    /**
     * 导出
     * @param startDate
     * @param endDate
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "导出", notes = "导出")
    @GetMapping({"/exportGroupDate"})
    @SysLog("所有运营商收入报表与对账数据复核导出")
    @PreAuthorize("@pms.hasPermission('view_ck_dataaudit_air_report_check_export')")
    public void exportExcel(String startDate, String endDate, HttpServletResponse response) {
        viewCkDataauditAirReportCheckService.exportExcel(startDate,endDate,response);
    }

    /**
     * 一键确认
     * @param listIds
     * @return
     */
    @ApiOperation(value = "西安地铁收入报表与对账数据复核一键确认", notes = "西安地铁收入报表与对账数据复核一键确认")
    @SysLog("西安地铁收入报表与对账数据复核一键确认")
    @PutMapping("/confirmBatch")
    public R confirmBatch(@RequestBody List<Integer> listIds) {
        LambdaUpdateWrapper<ViewCkDataauditAirReportCheck> updateWrapper = Wrappers.<ViewCkDataauditAirReportCheck>lambdaUpdate()
                .set(ViewCkDataauditAirReportCheck::getConformStatus, "1")
                .set(ViewCkDataauditAirReportCheck::getConformTime, LocalDateTime.now())
                .in(ViewCkDataauditAirReportCheck::getId, listIds);
        return R.ok(viewCkDataauditAirReportCheckService.update(updateWrapper));
    }
}
